home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / a_utils / expanded.lha / expanded / hdr / Matrix.h < prev    next >
C/C++ Source or Header  |  1992-03-19  |  5KB  |  192 lines

  1. //
  2. // Linear-Affine-Projective Geometry Package
  3. //
  4. // Matrix.h
  5. //
  6. // $Header$
  7. //
  8. // Austin Dahl and William J.R. Longabaugh 
  9. // University of Washington
  10. //
  11. // Copyright (c) 1990, 1991, 1992 Austin Dahl and William J.R. Longabaugh
  12. //   Copying, use and development for non-commercial purposes permitted.
  13. //   All rights for commercial use reserved.
  14. //   This software is unsupported and without warranty; it is
  15. //   provided "as is".
  16. //
  17. // Original implementation by Austin Dahl.  Modified by WJRL to eliminate
  18. // fixed maximum size and simplify operations on identity matrices.
  19. //
  20. // ***********************************************************************
  21.  
  22. #ifndef Matrix_h
  23. #define Matrix_h
  24.  
  25. #include <stream.h>
  26. #include "Lap1.h"
  27. #include "Object.h"
  28.  
  29. #ifndef MAX_LOCAL_DIMEN
  30. #define MAX_LOCAL_DIMEN 4
  31. #endif
  32.  
  33. // ***********************************************************************
  34.  
  35. class RowMatrix : public Object {
  36.   public:
  37.     // Constructors and Destructors
  38.  
  39.     RowMatrix();
  40.     RowMatrix(RowMatrix &m);
  41.     RowMatrix(int c);
  42.     RowMatrix(Scalar s0);
  43.     RowMatrix(Scalar s0, Scalar s1);
  44.     RowMatrix(Scalar s0, Scalar s1, Scalar s2);
  45.     RowMatrix(Scalar s0, Scalar s1, Scalar s2, Scalar s3);
  46.     ~RowMatrix();
  47.  
  48.     // Accessing Functions
  49.  
  50.     Scalar& operator[](int c);              // get cth element
  51.     int Columns();
  52.     friend RowMatrix AdjointRow(RowMatrix& rmat, int comit); // copy with row
  53.                                  // comit omitted
  54.  
  55.     // I/O
  56.  
  57.     friend ostream& operator<<(ostream& os, RowMatrix& rmat);
  58.     virtual void debug_out(ostream& os, int indent);
  59.  
  60.     // Assignment
  61.  
  62.     RowMatrix& operator=(RowMatrix& mat);      // everyday assignment
  63.     
  64.  
  65.   protected:
  66.     // Member Variables
  67.  
  68.     int      columns;                  // the size
  69.     Scalar  *rmr;                  // ptr to matrix
  70.     Scalar   local[MAX_LOCAL_DIMEN];              // local storage
  71.                           // for small matrices
  72. };
  73.  
  74. // ***********************************************************************
  75.  
  76. overload ZeroMatrix;
  77.  
  78. // ***********************************************************************
  79.  
  80. class Matrix : public Object {
  81.   public:
  82.     // Constructors and Destructors
  83.  
  84.     Matrix();
  85.     Matrix(Matrix &m);
  86.     Matrix(int r, int c);
  87.     Matrix(int dim);                  // for square matrices
  88.     Matrix(RowMatrix& rm0);
  89.     Matrix(RowMatrix& rm0, RowMatrix& rm1);
  90.     Matrix(RowMatrix& rm0, RowMatrix& rm1, RowMatrix& rm2);
  91.     Matrix(RowMatrix& rm0, RowMatrix& rm1, RowMatrix& rm2, RowMatrix& rm3);
  92.     ~Matrix();
  93.  
  94.     // Psuedo Constants (different for different sizes)
  95.  
  96.     friend Matrix ZeroMatrix(int r, int c);
  97.     friend Matrix ZeroMatrix(int dim);          // for square matrices
  98.     friend Matrix IdentityMatrix(int dim);      // for square matrices
  99.  
  100.  
  101.     // Accessing Functions
  102.  
  103.     RowMatrix& operator[](int r);          // get rth row
  104.     friend Matrix Adjoint(Matrix& mat, int romit, int comit); // copy with row
  105.                                   // romit and 
  106.                                   // column
  107.                                   // comit omitted
  108.  
  109.     int Rows();
  110.     int Columns();
  111.     Boolean Is_Identity(void);
  112.     void Set_Identity(Boolean val);    
  113.  
  114.     // Matrix Functions
  115.  
  116.     friend Scalar Det(Matrix& mat);          // determinite,
  117.                           // must be square matrix
  118.     friend Matrix Inverse(Matrix& mat);          // must be square matrix
  119.     friend Matrix Transpose(Matrix& mat);
  120.  
  121.     // Matrix Algrebra Operations
  122.  
  123.     friend Matrix operator+(Matrix& mat1,
  124.                 Matrix& mat2);      // addition
  125.     friend Matrix operator-(Matrix& mat1,
  126.                 Matrix& mat2);      // subtraction
  127.     friend Matrix operator-(Matrix& mat);      // negation
  128.     friend Matrix operator*(Matrix& mat1,
  129.                 Matrix& mat2);      // matrix multiply
  130.     friend Matrix operator*(Matrix& mat1,
  131.                 Scalar scal);      // scalar multiply
  132.     friend Matrix operator*(Scalar scal,
  133.                 Matrix& mat);      // scalar multiply
  134.     friend Matrix operator/(Matrix& mat,
  135.                 Scalar scal);      // scalar division
  136.  
  137.  
  138.     Matrix& operator=(Matrix& mat);          // everyday assignment
  139.     Matrix& operator+=(Matrix& mat);          // addition and assignment
  140.     Matrix& operator-=(Matrix& mat);          // subtract and assignment
  141.     Matrix& operator*=(Matrix& mat);          // matrix multiplication
  142.                           // and assignment
  143.     Matrix& operator*=(Scalar scal);          // scalar multiplication
  144.                           // and assignment
  145.     Matrix& operator/=(Scalar scal);          // scalar division
  146.                           // and assingment
  147.     
  148.     // I/O
  149.  
  150.     friend ostream& operator<<(ostream& os, Matrix& mat);
  151.     virtual void debug_out(ostream& os, int indent);
  152.  
  153.   protected:
  154.     // Member Variables
  155.  
  156.     Boolean     is_identity;
  157.     int         rows;                         // the size
  158.     int         columns;
  159.     RowMatrix  *mr;                  // ptr to matrix
  160.     RowMatrix   local[MAX_LOCAL_DIMEN];              // local storage
  161.                           // for small matrices
  162. };
  163.  
  164. // ***********************************************************************
  165.  
  166. inline int RowMatrix::Columns() {
  167.     return columns;
  168. }
  169.  
  170. inline int Matrix::Rows() {
  171.     return rows;
  172. }
  173.  
  174. inline int Matrix::Columns() {
  175.     return columns;
  176. }
  177.  
  178. inline Matrix ZeroMatrix(int dim) {
  179.     return ZeroMatrix(dim, dim);
  180. }
  181.  
  182. inline Matrix operator*(Scalar scal, Matrix& mat) {
  183.     return mat * scal;
  184. }
  185.  
  186. inline Boolean Matrix::Is_Identity(void) {return is_identity;}
  187. inline void Matrix::Set_Identity(Boolean val) {is_identity = val;}    
  188.  
  189. // ***********************************************************************
  190.  
  191. #endif
  192.